const pool = require('../tools/getPool');
const sendResponse = require('../tools/sendResponse');

module.exports = function(req, res){

	let id = req.body.id;
	let able = req.body.able;
	let name = req.body.name;

	let sql = '';
	let params = [];


	if (able != undefined) {
		sql = 'UPDATE module SET able = ? WHERE id = ?;';
		params.push(Number(able));
		params.push(Number(id));
	} else if (name != undefined) {
		sql = 'UPDATE module SET name = ? WHERE id = ?;';
		params.push(String(name));
		params.push(Number(id));
	} else {
		sendResponse('error','缺少内容，请检查', null, res);
		return; 
	}

	// 获取数据库连接
	pool.getConnection(function(err, connection) {
		if (err) {
			console.log(err);
			sendResponse('error','数据库内部错误', null, res);
			return;
		}
		// 执行语句
		connection.query(sql, params , function (error, rows, fields) {
			// 释放连接
			connection.release();

			if (error) { 
				console.log(error);
				sendResponse('error','数据库内部错误', null, res);
				return;
			}

			sendResponse('ok','操作成功', rows[0], res);

		})	

	});

}